package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.Drug_Manufacturer;
import com.ruoyi.project.drug.domain.Drug_Message;
import com.ruoyi.project.drug.domain.Drug_Supplier;
import com.ruoyi.project.drug.service.IDrug_SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/drug/supplier")
public class Drug_SupplierController extends BaseController {
    @Autowired
    private IDrug_SupplierService drug_supplierService;

    /*
     * 查询所以供应商信息
     * */
    @PreAuthorize("@ss.hasPermi('drug:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drug_Supplier drug_supplier) {
        startPage();
        List<Drug_Supplier> list = drug_supplierService.selectDrug_SupplierList(drug_supplier);
        return getDataTable(list);
    }

    /*
     * 添加供应商信息
     * */
    @PreAuthorize("@ss.hasPermi('drug:supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Drug_Supplier drug_supplier) {
        drug_supplier.setCreateBy(SecurityUtils.getUsername());
        return toAjax(drug_supplierService.insertDrug_Supplier(drug_supplier));
    }

    /*
     * 按条件查询供应商信息
     * */
    @PreAuthorize("@ss.hasPermi('drug:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable Long supplierId) {
        return AjaxResult.success(drug_supplierService.selectDrug_SupplierById(supplierId));
    }

    /*
     * 修改供应商信息
     * */
    @PreAuthorize("@ss.hasPermi('drug:supplier:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Drug_Supplier drug_supplier) {
        drug_supplier.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(drug_supplierService.updateDrug_Supplier(drug_supplier));
    }

    /*
    * 删除供应商信息
    * */
    @PreAuthorize("@ss.hasPermi('drug:supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds) {
        return toAjax(drug_supplierService.deleteDrug_SupplierById(supplierIds));
    }
}
